#
# @lc app=leetcode.cn id=257 lang=python3
#
# [257] 二叉树的所有路径
#
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
from typing import List, Optional
# @lc code=start
# Definition for a binary tree node.
class Solution:
    def binaryTreePaths(self, root: Optional[TreeNode]) -> List[str]:
        if root is None:
            return []
        self.all_path = []
        self.preorder(root, "")
        return self.all_path
    
    def preorder(self, root:TreeNode, path: str) -> None:
        temp_path = path + str(root.val)
        if root.left is None and root.right is None:
            self.all_path.append(temp_path)
            return
        if root.left:
            self.preorder(root.left, temp_path + "->")
        if root.right:
            self.preorder(root.right, temp_path + "->")


        
# @lc code=end

